#include <map>
#include <vector>
using namespace std;

class Solution {
public:

    //解法一：哈希表+双指针
    int removeDuplicates(vector<int>& nums) 
    {
        map<int, int> mymap; // 创建哈希表键值表示nums中的元素，映射值表示元素个数
        int res = 0;
        for (const auto& num : nums) 
        {
            mymap[num]++;
            if (1==mymap[num])//通过哈希表的映射确定那个(键值)数组元素没有重复
            {
                nums[res++] = num;
            }
        }
        return res;
    }

    //解法二：快慢指针1
	int deleteElement_(vector<int>& v)
	{
		if (0 == v.size())
			return;
		int fast = 1, slow = 1;
		while (fast < v.size()) 
		{
			if (v[fast] != v[fast - 1]) 
			{
				v[slow] = v[fast];
				++slow;
			}
			++fast;
		}
		return slow;
	}

	//快慢指针2
	int deleteElement_1(vector<int>& v)
	{
		if (0 == v.size())
			return 0;
		int left = 0;
		for (int i = 1;i < v.size();i++)
		{
			if (v[i] == v[i - 1])
				continue;
			else
				v[++left] = v[i];
		}
		return left + 1;
	}
};